﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WxSDK
{
    public class WeChatJsAPI : System.Web.UI.Page
    {
        #region 微信JSAPI相关

        /// <summary>
        /// 获取js签名相关
        /// </summary>
        /// <param name="url">页面地址 , 动态传入这样可以让很多页面都有JSAPI的权限</param>
        /// <returns></returns>
        public static WeChatModel.JsApiTicket GetJsApi_Signature(string url)
        {

            WxSDK.Model.wx_member model = WxSDK.CacheSys.WeChatMemory.MemberInfo(WeChatConf.MemberId());

            //Dictionary<string, string> parameters = new Dictionary<string, string>();//请求参数，类型为关联数组
            WeChatModel.JsApiTicket JsApiTicket = new WeChatModel.JsApiTicket();
            JsApiTicket.appid = model.APPID;//公众账号ID
            JsApiTicket.timestamp = WeChat_Pub.ConvertDateTimeInt().ToString();
            JsApiTicket.nonceStr = WeChatCommon.CreatNonceStr();
            //http://activity.runjindian.com/myred_i.aspx url 不需要参数
            string signature = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("jsapi_ticket=" + WeChatApi.GetJsApiTicket(WeChatConf.MemberId()) + "&noncestr=" + JsApiTicket.nonceStr + "&timestamp=" + JsApiTicket.timestamp + "&url=" + url, "SHA1");
            JsApiTicket.signature = signature.ToLower();
            return JsApiTicket;
        }

        #endregion
    }
}
